<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>时间</title>
        <script>
            var myTime = function() {
                var d = new Date();//表明生成了一个日期对象
                var year = d.getFullYear();
                var month = d.getMonth();//从0开始
                var date = d.getDate();
                var week = d.getDay();
                var hour = d.getHours();
                var minute = d.getMinutes();
                var second = d.getSeconds();
                var ms = d.getMilliseconds();
                var pv = document.getElementById('p1');
                pv.textContent = '今天是 : 星期' + week + ' ' + year + '年' + (month + 1) + '月' + date + '日' + hour + ':' + minute + ':' + second;
            };
            window.onload = function() {
                //setInterval 按照时间 间隔来循环执行
                //参数1: 脚本内容
                //参数2: 时间单位 (ms) 1000ms = 1s
                myTime();
                window.setInterval(myTime, 100);

            };
        </script>
    </head>
    <body>
        <div id="p1"></div>
    </body>
</html>